<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function countingSort(nums) {
        let arr = [];
        let max = Math.max(...nums);
        let min = Math.min(...nums);

        for (let i = 0, len = nums.length; i < len; i++) {
          let temp = nums[i];
          arr[temp] = arr[temp] + 1 || 1;
        }
        let index = 0;

        for (let i = min; i <= max; i++) {
          while (arr[i] > 0) {
            nums[index++] = i;
            arr[i]--;
          }
        }
        return nums;
      }

      console.log(countingSort([1, 2, 5, 4, 3, 10]));
    </script>
  </body>
</html>
